package cn.caplike.demo.google.protobuf.with_netty_multi;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Description:
 *
 * @author LiKe
 * @version 1.0.0
 * @date 2021-12-01 13:08
 */
public class TestServerChannelInboundHandler extends SimpleChannelInboundHandler<MyMultiDataInfo.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyMultiDataInfo.MyMessage msg) {
        MyMultiDataInfo.MyMessage.DataType dataType = msg.getDataType();

        if (dataType == MyMultiDataInfo.MyMessage.DataType.PersonType) {
            MyMultiDataInfo.Person person = msg.getPerson();
            System.out.println(person.getName());
        } else if (dataType == MyMultiDataInfo.MyMessage.DataType.DogType) {
            MyMultiDataInfo.Dog dog = msg.getDog();
            System.out.println(dog.getName());
        } else {
            MyMultiDataInfo.Cat cat = msg.getCat();
            System.out.println(cat.getName());
        }
    }
}
